/*
 * @Author: hyq
 * @LastEditors: hyq
 * @Description:
 * @Date: 2023-12-26 10:31:35
 */
import { defineConfig, loadEnv } from 'vite'
import path from 'path'
import uni from '@dcloudio/vite-plugin-uni'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'
import Components from '@uni-helper/vite-plugin-uni-components'
import { NutResolver } from 'nutui-uniapp'
import UnoCSS from 'unocss/vite'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      OptimizationPersist(),
      PkgConfig(),
      Components({
        resolvers: [NutResolver()]
      }),
      UnoCSS({ mode: 'vue-scoped', configFile: './unocss.config.ts' }),
      uni()
    ],
    resolve: {
      alias: {
        '@': path.join(__dirname, './src')
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "nutui-uniapp/styles/variables.scss";`
        }
      }
    },
    publicDir: env.VITE_APP_PUBLICDIR,
    server: {
      proxy: {
        '/apis': {
          // target: 'http://localhost:5000',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/apis/, '')
        }
      }
    }
  }
})
